package com.gmstu.springframework.aop.aspect;

import com.gmstu.springframework.aop.intercept.GpMethodInterceptor;
import com.gmstu.springframework.aop.intercept.GpMethodInvocation;

import java.lang.reflect.Method;

/**
 * @author John.zhang
 * @version Id: GpMethodAfterAdviceInterceptor, v 1.0 2020/8/26 17:38 ZhiYong Exp $
 */
public class GpMethodReturningAdviceInterceptor extends GpAbstractAspectAdvice implements GpMethodInterceptor {

    private GpJoinPoint joinPoint;

    public GpMethodReturningAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    private void afterReturning(Object returnValue, Method method, Object aThis) throws Throwable {
        super.invokeAdviceMethod(this.joinPoint, returnValue, null);
    }

    @Override
    public Object invoke(GpMethodInvocation invocation) throws Throwable {
        Object returnValue = invocation.proceed();
        this.joinPoint = invocation;
        this.afterReturning(returnValue, invocation.getMethod(), invocation.getThis());
        return returnValue;
    }
}
